import Router from '@koa/router'
import { loginController, whoAmI } from './apis/login'
import { chatControllerForCase, chatControllerForQuestion, chatControllerForQuestionPoint, chatControllerForRichText } from './apis/chat'
import Application from 'koa'
import { add, del, getDict, getList, update } from './apis/commonCrud'
import { upload, uploadKnowledgeBase } from './apis/upload'
import { getListUnauth } from './apis/unauthCrud'
import { getHotList } from './apis/hot'
import multer from '@koa/multer'
import { delKnowledgeBaseFile } from './apis/knowledgeBase'

const router = new Router()
const uploadMulter = multer()

// 登录
router.post('/login', loginController)
// 获取当前登录的用户信息
router.get('/whoami', whoAmI)
// 教学案例问答ai聊天
router.post('/chat', chatControllerForCase)
// 文章润色ai聊天
router.post('/writing-chat', chatControllerForRichText)
// 问题知识点生成
router.post('/question-point-gen-chat', chatControllerForQuestionPoint)
// 问题生成
router.post('/question-gen-chat', chatControllerForQuestion)

// 公用的增删改查
router.post('/unauth-crud/getList/:modelName', getListUnauth)

// 获取热门列表
router.post('/hot/getList/:modelName', getHotList)

// 获取字典
router.get('/dict/:modelName', getDict)

// 管理面板的增删改查
router.post('/crud/getList/:modelName', getList)
router.post('/crud/:modelName', add)
router.put('/crud/:modelName/:id', update)
router.delete('/crud/:modelName/:id', del)

// 知识库文件上传
router.post('/knowledge-base/upload', uploadMulter.array('file'), uploadKnowledgeBase)
// 知识库文件删除
router.post('/knowledge-base-file/del', delKnowledgeBaseFile)

// 文件上传
router.post('/upload', uploadMulter.array('file'), upload)

export const registerRouter = (app: Application) => {
    app.use(router.routes()).use(router.allowedMethods())
}
